package com.example.helloandroid;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.util.Enumeration;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.widget.TextView;

public class HelloAndroid extends Activity  {
    /** Called when the activity is first created. */
	
	public static Handler handler = new Handler();
	public static TextView TV;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this); 
        TV = tv;
        tv.setText(getLocalIpAddress()); 
        
        final HelloAndroid fart = this;
//        Thread t = new Thread(){ 
//        	public void run(){ 
//        		startService(new Intent(fart, ServerService.class));  
//        		} 
//        	};
//  
//        		t.start();
        		
        		startService(new Intent(fart, ServerService.class));
        		setContentView(tv);


    }
    
    public void onStart(){
    	super.onStart();

    	
    }
    
    public String getLocalIpAddress() {
        try {
            for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
                NetworkInterface intf = en.nextElement();
                for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                    InetAddress inetAddress = enumIpAddr.nextElement();
                    if (!inetAddress.isLoopbackAddress()) {
                        return inetAddress.getHostAddress().toString();
                    }
                }
            }
        } catch (SocketException ex) {
            Log.e("hi", ex.toString());
            return ex.toString();
        }
        return "silly";
    }

}

 
